package com.yh.test;

import com.yh.dao.ITopicDao;
import com.yh.dao.IUserDao;
import com.yh.entity.Reply;
import com.yh.entity.Topic;
import com.yh.entity.User;
import com.yh.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.List;

public class Demo1 {
    SqlSession session=null;
    IUserDao iud=null;
    ITopicDao itd=null;
@Before
    public void init(){
        session= SqlSessionFactoryUtil.getSqlSession();
        iud=session.getMapper(IUserDao.class);
        itd=session.getMapper(ITopicDao.class);
    }

    @Test
    public void test1(){

       User u=iud.getUser(3);
        //System.out.println(u.getTopicList());
       List<Topic> list= u.getTopicList();
       List<Reply> list1=u.getReplyList();
        for (Topic t:list) {
           System.out.println(u.getUname()+"====="+t.getFtitle());
        }
        System.out.println("--------------");
        for (Reply r:list1) {
            System.out.println(u.getUname()+"====="+r.getHcontext());
        }
    }
    @Test
    public void test2(){
       List<Topic> list=itd.getTopicAll();
        for (Topic t:list) {

            System.out.println(t.getFtitle()+","+t.getUid().getUname());

        }

    }


    @After
    public void destory(){
        session.close();
    }
}
